// Framework: None
// Technology stack: None

#include <iostream>
#include <unordered_map>
#include <string>
#include <cmath>

std::unordered_map<std::string, int> number_dict = {{"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4}, {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}};

bool check_prime(int number) {
    if (number <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(number); i++) {
        if (number % i == 0) {
            return false;
        }
    }
    return true;
}

int find_closest_prime(int number) {
    if (!std::is_same<int>(number) || number < 100 || number > 999) {
        return "wrong input";
    }

    if (check_prime(number)) {
        return number;
    }

    int lower_prime = number;
    int upper_prime = number;
    while (!check_prime(lower_prime)) {
        lower_prime--;
    }
    while (!check_prime(upper_prime)) {
        upper_prime++;
    }

    if (abs(number - lower_prime) <= abs(number - upper_prime)) {
        return lower_prime;
    } else {
        return upper_prime;
    }
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::vector<std::string> word_list;
    std::istringstream iss(input);
    for (std::string word; iss >> word;) {
        word_list.push_back(word);
    }

    int number = 0;

    if (word_list.size() == 3) {
        for (const std::string& word : word_list) {
            if (number_dict.find(word) == number_dict.end()) {
                std::cout << "wrong input" << std::endl;
                break;
            }
            number = number * 10 + number_dict[word];
        }
        std::cout << find_closest_prime(number) << std::endl;
    } else {
        std::cout << "wrong input" << std::endl;
    }

    return 0;
}